package com.servlet;

import com.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/ServletDelete")
public class ServletDelete extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("name");
        StudentService stu = new StudentService();
        Boolean b = stu.delete(id);
        if (b){
            resp.sendRedirect("/ServletFind");
        }else{
            resp.getWriter().write("删除失败");
            resp.setHeader("Refresh","2;URL=/ServletFind");
        }
    }
}
